home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: spdcool@ix.netcom.com(SPD)
- Newsgroups: comp.lang.c
- Subject: I need help on putting 2 strings together into 1(concatenate)
- Date: 20 Feb 1996 15:57:31 GMT
- Organization: Netcom
- Message-ID: <4gcr1b$ft3@cloner4.netcom.com>
- NNTP-Posting-Host: ix-nyc16-01.ix.netcom.com
- X-NETCOM-Date: Tue Feb 20 7:57:32 AM PST 1996
-
- Hi,
-
- I figured out my earlier problem. Thanks to all that helped. Now I
- have another problem. First take a look at a short version of my code:
- To conserve time, I didn't use any user define constants
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <time.h>
- struct data {
- char *full_name;
- int age;
- float salary;
- };
-
- struct name {
- char *first1, *last1;
- };
-
-
- int main(void)
- {
- struct name fname[3], lname[3];
- struct data secret[5];
- int i, ran;
-
- fname[o].first1 = "Joe";
- fname[1].first1 = "Michael";
- fname[2].first1 = "Bruce";
- lname[0].last1 = "Jordan";
- lname[1].last1 = "Willis";
- lname[2].last1 = "Jackson";
-
- randomize()
- for (i = 0; i < 5; ++i) {
- e = random(3);
- secret[i].full_name = fname[e].first1;/* the trouble some part begin
- e = random(3);
- strcat(secret[i].full_name," ");
- strcat(secret[i].full_name,lname[e].last1); /*trouble ends here*/
- "
- "
- " /* the rest works */
- " }
- for (i = 0; i < 5; ++i) {
- printf("%s%s",secret[i].full_name, " ");
- printf("%d%s%5.2f\n", secret[i].age," ",secret[i].salary);
- }
- return 0;
- }
-
- I've stated the trouble some part above. What I want to do is this:
-
- The computer randomly picks a first name, let's say: Michael
- Then the computer picks a last name: Jordan
- These are two separate strings. I want to pit these strings together
- to form: Michael Jordan.
- Then printed out. Of course I have to do more than 1 name. My
- orginal code is much longer(I am given 15 first names and 20 last
- names). I have to form 50 names from it. Can you fix my code?
- Thanks in advance for the help.
-
- please e-mail me at spdcool@ix.netcom.com and spd7398@acf4.nyu.edu
- mail me at both places b/c I may be at home or in school
-
-